<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<div class="modal-body">
    <div class="row">
        <div class="col-md-12">
            <form id="permission_save_input" class="form-horizontal" action="" method="post">
                <input type="hidden" name="keyId" id="keyId" key="keyId" value="<s:property value="permission.id" />">
 				<input type="hidden" id="rdbType" value="<s:property value="permission.type"/>"/>               
                <fieldset>
                    <legend>
                        <s:if test="permission==null">
                            <span class="label  label-warning"> [添加资源]</span>
                        </s:if>
                        <s:else>
                            <span class="label  label-warning"> [更新资源]</span>
                        </s:else>
                    </legend>
                    <div class="form-group">
                        <label class="col-md-3 control-label">名称</label>
                        <div class="col-md-9">
                            <input class="form-control" name="name" id="name" placeholder="请输入名称"
                                type="text" value="<s:property value="permission.name" />">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">排序编码</label>
                        <div class="col-md-9">
                            <input class="form-control" name="sortNumber" id="sortNumber" placeholder="请输入排序编码"
                                type="number" value="<s:property value="permission.sortNumber" />">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">上级节点</label>
                        <div class="col-md-9">
                            <s:if test="permission.parent.name!=null">
                                <input class="form-control" type="text" name="fid" id="fid" onfocus="showTree()" value="<s:property value="permission.parent.name" />"/>
                            </s:if>
                            <s:else>
                                <input class="form-control" type="text" name="fid" id="fid" onfocus="showTree()" value="<s:property value="" />"/>
                            </s:else>
                            <input type="hidden" name="parentId" id="parentId" value="<s:property value="permission.parent.id" />"/>
                            <div id="tree_menu" class="col-md-11" style="display:none;position:absolute;overflow:auto;background: #fff ;z-index: 99;height: 150px;border: 1px solid #ccc">
                                <ul id="pTree" class="ztree" style="margin-top:0; width:180px; height: 100px;"></ul>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">资源类型</label>
                        <div class="col-md-9">
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" id="menu" name="type" value="menu"/>
                            	<span>菜单</span>
                            </label>
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" id="action" name="type" value="action"/>
                                <span>操作</span>
                            </label>
                            <label class="radio radio-inline">
                                <input type="radio" class="radiobox" id="navigation" name="type" value="navigation"/>
                                <span>导航</span>
                            </label>

                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-3 control-label">资源图标</label>
                        <div class="col-md-9">
                            <input class="form-control" name="iconCls" id="iconCls" placeholder="资源图标" type="text" value="<s:property value="permission.iconCls" />">
                        </div>
                    </div>
                    <div class="form-group" id="iconDiv" style="display: none">
                        <label class="col-md-3 control-label">图标颜色</label>
                        <div class="col-md-9">
                            <input class="form-control" name="iconcolor" id="iconcolor" placeholder="图标颜色" type="text" value="<s:property value="permission.iconcolor" />">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">资源路径</label>
                        <div class="col-md-9">
                            <input class="form-control" name="url" id="url" placeholder="请输入资源路径"
                                type="text" value="<s:property value="permission.url" />">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">关键字</label>
                        <div class="col-md-9">
                            <input class="form-control" name="businessKey" id="businessKey" placeholder="请输入关键字"
                                type="text" value="<s:property value="permission.businessKey" />">
                        </div>
                    </div>

                </fieldset>
            </form>
        </div>
    </div>
    <input id="pType"  hidden value="<s:property value="permission.type" />">
</div>

<div class="modal-footer">
	<a href="#ajax!permission.action" class="btn btn-primary" id="dialog-ok">确定</a>
	<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
</div>
<script>
$(function(){
    var rdbType=$("#rdbType").val();
    switch (rdbType){
        case 'menu':
            $("#menu").attr("checked","true");
            break;
        case 'action':
            $("#action").attr("checked","true");
            break;
        case 'navigation':
            $("#navigation").attr("checked","true");
            $("#iconDiv").show();
            break;
    }
    $("input#fid").treeSelect('init',{
        actionUrl:"ajax-permission!zTree.action"
    });
});
$("#dialog-ok").unbind("click").bind("click",function(){
    var actionUrl = "<%=path%>/com/ajax-permission!save.action";
    form_save("permission_save_input",actionUrl);

    if($("input[key='keyId']").val() != ""){
        jQuery("#ajax_permission_list_table").trigger("reloadGrid");
    }else{
        loadURL("ajax!permission.action",$('#content'));
    }
    gDialog.fClose();
});
function showTree(){
    $("#tree_menu").slideDown();
    $("input#fid").treeSelect('show');
}
$("input[name=type]").unbind().bind("click",function(e){
    if($("#navigation").prop("checked") && $(this).val() == "navigation"){
        $("#iconDiv").show();
    }
    else{
        $("#iconDiv").hide();
    }
});
</script>